<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>任务1</title>
  <style>
    body {
      height: 10000px;
      background: #eee;
    }

    #showScroll {
      font-size: 30px;
      /* 固定定位（相对于浏览器窗口） */
      position: fixed;
      /* 相对浏览器窗口，左上角 */
      top: 0;
    }
  </style>
</head>

<body>
  <p id="showScroll">0px</p>
  <script>
    const showScroll = document.querySelector('#showScroll')
    window.addEventListener('scroll', function () {
      showScroll.innerHTML = parseInt(document.documentElement.scrollTop) + 'px'
    }
    )
  </script>
</body>

</html>